﻿$(document).ready(function () {

    $('body').css('position', 'relative');
    $('body').append('<div class="freeze" style="display:none;background-color: #fff; left: 0px; position: absolute; top: 0px; width: 100%; opacity: 0.5; z-index: 99999; height: 102%;"></div>');
    $('body').append('<div class="processing" style="display:none;z-index: 999999;margin-right: -51px; background-color: #676767; border-radius: 0px 0px 6px 6px; padding: 0px 10px; position: fixed; right: 50%; top: 0px;"><div style="background: url(/components/com_payment/images/processing.gif) no-repeat scroll 3px center transparent; color: rgb(255, 255, 255); font-weight: bold; padding: 6px 0px 6px 27px;">' + $("#processing").val() + '</div></div>');

    //$('input[type="radio"]:checked')
    $('input[type="radio"]').live('click', function () {
        var alt_attr = ($(this).attr('alt'));
        var name_attr = ($(this).attr('name'));
        $('input[name="' + name_attr + '"]').each(function () {
            var t = $(this).attr('alt');
            $('.giftUnit_' + t).attr('disabled', 'disabled');
            $('.giftImg_' + t).removeClass('active');
        });
        $('.giftUnit_' + alt_attr).removeAttr('disabled');
        $('.giftImg_' + alt_attr).addClass('active');
    });
    $('.giftImg img').live('click', function () {
        $(this).parent().prev().find('input[type="radio"]').trigger('click');
    });

    $(".district_" + $(".city").val()).addClass("active");
    $(".city").change(function () {
        id = $(this).val();
        $(".district").each(function () {
            $(this).removeClass("active")
        });
        $(".district_" + id).addClass("active")
    });
    $(".commented_view").append('<span class="loading"><img src="/components/com_user/img/loading.gif" title="loading"></span>');
    $(".loading").hide();
    $(".images li").click(function () {
        var a = $("img", this).attr("alt");
        a = "" + a;
        if (a.indexOf("big_") != -1) {
            $(".main_img").find("a").attr({
                href: a,
                rel: "position: 'inside', showTitle: false, lensOpacity: 0.7"
            });
            $(".main_img").find("a").addClass("cloud-zoom");
            $(".main_img").find("img").attr("src", a);
            $(".cloud-zoom, .cloud-zoom-gallery").CloudZoom();
            $(".zoomwrap").css("display", "block")
        } else {
            $("#wrap").remove();
            $(".main_img > a").remove();
            $(".main_img").html("<a><img></a>" + $(".main_img").html());
            $(".main_img").find("img").attr("src", a);
            $(".zoomwrap").css("display", "none")
        }
    });
    if ($("#buy_active").val() != "0") {
        $("#buynow, #addtocart").addClass("disabled")
    }
    if ($("#city_time").val() == 1) {
        $(".hcmCity").show()
    } else {
        $(".othersCity").show()
    }
    $("#city_time").live("change", function () {
        if ($("#city_time").val() == 1) {
            $(".hcmCity").show();
            $(".othersCity").hide()
        } else {
            $(".othersCity").show();
            $(".hcmCity").hide()
        }
    });
    if ($(".status_" + $("#unit_code").val()).length) {
        //$(".status_" + $("#unit_code").val()).show()
        $(".stock_status").html($(".status_" + $("#unit_code").val()).html());
    }
    $("#unit_code").live("change", function () {
        if ($(".status_" + $(this).val()).length) {
            if ($(this).val() != "") {
                //				$(".status").each(function() {
                //					$(this).hide()
                //				});
                //				$(".status_" + $(this).val()).show()
                $(".stock_status").html($(".status_" + $(this).val()).html());
            } else {
                //$(".status").hide()
                $(".stock_status").empty();
            }
        } else {
            //$(".status").hide()
            $(".stock_status").empty();
        }
    });
    if ($(".deli_" + $("#size_color").val()).length) {
        $(".deli_" + $("#size_color").val()).show()
    }
    if ($(".city_" + $("#size_color").val()).length) {
        $(".city_" + $("#size_color").val()).show()
    }
    if ($(".dtl_" + $("#size_color").val()).length) {
        $(".dtl_" + $("#size_color").val()).css("display", "block")
    }
    $("#size_color").live("change", function () {
        if ($(".deli_" + $(this).val()).length) {
            if ($(this).val() != "") {
                $(".deli").each(function () {
                    $(this).hide()
                });
                $(".deli_" + $(this).val()).show()
            } else {
                $(".deli").hide()
            }
        } else {
            $(".deli").hide()
        }
        if ($(".city_" + $(this).val()).length) {
            if ($(this).val() != "") {
                $(".city").each(function () {
                    $(this).hide()
                });
                $(".city_" + $(this).val()).show();
                $(".district").each(function () {
                    $(this).removeClass("active")
                });
                $(".district_" + $(".city_" + $(this).val()).val()).addClass("active")
            } else {
                $(".city").hide()
            }
        } else {
            $(".city").hide()
        }
        if ($(".dtl_" + $(this).val()).length) {
            if ($(this).val() != "") {
                $(".dtl").each(function () {
                    $(this).hide()
                });
                $(".dtl_" + $(this).val()).css("display", "block")
            } else {
                $(".dtl").hide()
            }
        } else {
            $(".dtl").hide()
        }
    });
    $(".images").show();
    $(".scjGift_img").show();
    $(".freeGift_img").show();
    $("#jcarousel_detail_img").jcarousel({
        scroll: 1
    });
    $("a.videoLink").colorbox({
        title: 'false',
        iframe: true,
        innerWidth: 650,
        innerHeight: 480,
        onLoad: function () {
            $("#cboxClose").hide()
            $("#cboxTopLeft").hide()
            $("#cboxTopCenter").hide()
            $("#cboxTopRight").hide()
            $("#cboxMiddleLeft").hide()
            $("#cboxMiddleRight").hide()
            $("#cboxBottomLeft").hide()
            $("#cboxBottomCenter").hide()
            $("#cboxBottomRight").hide()
            $("#colorbox").css("width", "630px");
            $("#colorbox").css("height", "440px");
        },
        onComplete: function () {
            $("#colorbox").css("width", "630px");
            $("#colorbox").css("height", "440px");
        }
    });
    var b = false;
    $("#contentWrap").hover(function () {
        b = true
    }, function () {
        b = false
    });
    $("body").click(function (a) {
        if (b == false && $(a.target).hasClass("delivery_check") == false && $("#popupContainer").css("display") != "none") {
            $("#popupContainer").css({
                visibility: "visible",
                display: "block"
            }).hide(400)
        }
    });
    $(".closepopup").click(function () {
        $("#popupContainer").css({
            visibility: "visible",
            display: "block"
        }).hide(400)
    });
    $(".delivery_check").click(function () {
        if ($("#unit_code").val() == "") {
            showMessage($("#alert1").val())
        } else {
            if ($("#popupContainer").css("display") == "none") {
                var e = $("#itemCode").val();
                var a = $("#unit_code").val();
                var d = $("#lang").val();
                $.ajax({
                    type: "POST",
                    url: "index.php?option=com_catalogue&task=checkDelivery",
                    data: {
                        itemCode: e,
                        unitCode: a,
                        lang: d
                    },
                    success: function (c) {
                        if (c.length > 0) {
                            $("#contentWrap").html(c);
                            $("#popupContainer").css({
                                top: $(".delivery_check").position().top + 20 + "px",
                                left: "130px"
                            });
                            $("#popupContainer").css({
                                visibility: "visible",
                                display: "none"
                            }).show(400)
                        }
                    }
                })
            }
        }
    });
    $("#buynow").click(function () {
        if ($("#buy_active").val() == "0") {
            if ($("#unit_code").val() == "") {
                showMessage($("#alert1").val())
            } else {
                $.ajax({
                    type: "POST",
                    url: "index.php?option=com_catalogue&task=checkUserLogIn",
                    success: function (c) {
                        if (parseInt(c) > 0) {
                            if ($("#buy_active").val() == "0") {
                                if ($("#unit_code").val() == "") {
                                    showMessage($("#alert1").val())
                                } else {
                                    addToCartSubmit(1)
                                }
                            }
                        } else {
                            var a = '<div id="login_wrap">' + $("#login_wrap_hidden").html() + "</div>";
                            $.mycolorbox({
                                title: $('#loginTitle').val(),
                                html: a,
                                transition: "none",
                                onComplete: function () {
                                    $(".login_form .email").focus();
                                    $("#login_wrap").find(".login").click(function () {
                                        var d = $("#login_wrap").height();
                                        var g = $("#login_wrap").find(".email").val();
                                        var m = $("#login_wrap").find(".passwd").val();
                                        var j = $("#cur_url").val();
                                        var h = $("#login_wrap .login_form input:last").attr("name");
                                        var e = $("#login_wrap .login_form input:last").val();
                                        var k = $("#login_wrap").find(".remember").is(":checked") ? 1 : 0;
                                        if ($.trim(g) == "") {
                                            $("#login_wrap .message").html($("#alert6").val());
                                            $("#login_wrap .email").focus()
                                        } else {
                                            if (m == "") {
                                                $("#login_wrap .message").html($("#alert7").val());
                                                $("#login_wrap .passwd").focus()
                                            } else {
                                                if (checkEmail(g) && m != "") {
                                                    $.ajax({
                                                        type: "POST",
                                                        url: "index.php?option=com_user&task=login",
                                                        data: "username=" + g + "&passwd=" + m + "&remember=" + k + "&is_ajax=" + 1 + "&return=" + j + "&" + h + "=" + e,
                                                        success: function (n) {
                                                            if (parseInt(n) > 3) {
                                                                $("#login_wrap .message").html($("#alert11").val()).css('color', 'green');
                                                                //                                                                setTimeout(function(){$.colorbox.close()}, 2000);
                                                                var l = $("#login_wrap").height();
                                                                resizeMyColorBox(parseInt(l) - parseInt(d))
                                                                addToCartSubmit(1)
                                                            } else {
                                                                if (parseInt(n) == 0) {
                                                                    $("#login_wrap .message").html($("#alert8").val())
                                                                } else {
                                                                    if (parseInt(n) == 2) {
                                                                        $("#login_wrap .message").html($("#alert9").val())
                                                                    } else {
                                                                        $("#login_wrap .message").html($("#alert10").val())
                                                                    }
                                                                }
                                                                var l = $("#login_wrap").height();
                                                                resizeMyColorBox(parseInt(l) - parseInt(d))
                                                            }
                                                        }
                                                    })
                                                } else {
                                                    $("#login_wrap .message").html($("#alert5").val());
                                                    $("#login_wrap .email").focus()
                                                }
                                            }
                                        }
                                        var f = $("#login_wrap").height();
                                        resizeMyColorBox(parseInt(f) - parseInt(d))
                                    });
                                    $("#login_wrap").find(".passwd").keyup(function (d) {
                                        if (d.keyCode == 13) {
                                            $("#login_wrap").find(".login").trigger("click")
                                        }
                                    });
                                    $("#login_wrap").find(".remember").keyup(function (d) {
                                        if (d.keyCode == 13) {
                                            $("#login_wrap").find(".login").trigger("click")
                                        }
                                    })
                                }
                            })
                        }
                    }
                })
            }
        }
    });
    $("#addtocart").click(function () {
        if ($("#buy_active").val() == "0") {
            if ($("#unit_code").val() == "") {
                showMessage($("#alert1").val())
            } else {
                $.ajax({
                    type: "POST",
                    url: "index.php?option=com_catalogue&task=checkUserLogIn",
                    success: function (c) {
                        if (parseInt(c) > 0) {
                            if ($("#buy_active").val() == "0") {
                                if ($("#unit_code").val() == "") {
                                    showMessage($("#alert1").val())
                                } else {
                                    addToCartSubmit(0)
                                }
                            }
                        } else {
                            var a = '<div id="login_wrap">' + $("#login_wrap_hidden").html() + "</div>";
                            $.mycolorbox({
                                title: $('#loginTitle').val(),
                                html: a,
                                transition: "none",
                                onComplete: function () {
                                    $(".login_form .email").focus();
                                    $("#login_wrap").find(".login").click(function () {
                                        var d = $("#login_wrap").height();
                                        var g = $("#login_wrap").find(".email").val();
                                        var m = $("#login_wrap").find(".passwd").val();
                                        var j = $("#cur_url").val();
                                        var h = $("#login_wrap .login_form input:last").attr("name");
                                        var e = $("#login_wrap .login_form input:last").val();
                                        var k = $("#login_wrap").find(".remember").is(":checked") ? 1 : 0;
                                        if ($.trim(g) == "") {
                                            $("#login_wrap .message").html($("#alert6").val());
                                            $("#login_wrap .email").focus()
                                        } else {
                                            if (m == "") {
                                                $("#login_wrap .message").html($("#alert7").val());
                                                $("#login_wrap .passwd").focus()
                                            } else {
                                                if (checkEmail(g) && m != "") {
                                                    $.ajax({
                                                        type: "POST",
                                                        url: "index.php?option=com_user&task=login",
                                                        data: "username=" + g + "&passwd=" + m + "&remember=" + k + "&is_ajax=" + 1 + "&return=" + j + "&" + h + "=" + e,
                                                        success: function (n) {
                                                            if (parseInt(n) > 3) {
                                                                $("#login_wrap .message").html($("#alert11").val()).css('color', 'green');
                                                                //setTimeout(function(){$.mycolorbox.close()}, 2000);
                                                                var l = $("#login_wrap").height();
                                                                resizeMyColorBox(parseInt(l) - parseInt(d))
                                                                addToCartSubmit(0);
                                                                //																setTimeout(function() {
                                                                //																	location.reload()
                                                                //																}, 500)
                                                            } else {
                                                                if (parseInt(n) == 0) {
                                                                    $("#login_wrap .message").html($("#alert8").val())
                                                                } else {
                                                                    if (parseInt(n) == 2) {
                                                                        $("#login_wrap .message").html($("#alert9").val())
                                                                    } else {
                                                                        $("#login_wrap .message").html($("#alert10").val())
                                                                    }
                                                                }
                                                                var l = $("#login_wrap").height();
                                                                resizeMyColorBox(parseInt(l) - parseInt(d))
                                                            }
                                                        }
                                                    })
                                                } else {
                                                    $("#login_wrap .message").html($("#alert5").val());
                                                    $("#login_wrap .email").focus()
                                                }
                                            }
                                        }
                                        var f = $("#login_wrap").height();
                                        resizeMyColorBox(parseInt(f) - parseInt(d))
                                    });
                                    $("#login_wrap").find(".passwd").keyup(function (d) {
                                        if (d.keyCode == 13) {
                                            $("#login_wrap").find(".login").trigger("click")
                                        }
                                    });
                                    $("#login_wrap").find(".remember").keyup(function (d) {
                                        if (d.keyCode == 13) {
                                            $("#login_wrap").find(".login").trigger("click")
                                        }
                                    })
                                }
                            })
                        }
                    }
                })
            }
        }
    });
    $("#addwishlist").click(function () {
        var a = $("#productID").val();
        var d = $("#lang").val();
        $("#addwishlist").hide();
        $.ajax({
            type: "POST",
            url: "index.php?option=com_catalogue&task=add_wishlist",
            data: "product_id=" + a,
            success: function (c) {
                showConfirm($("#addwishlist_confirm").val())
            }
        });
        $("#removewishlist").show()
    });
    $("#removewishlist").click(function () {
        var a = $("#productID").val();
        var d = $("#lang").val();
        $("#removewishlist").hide();
        $.ajax({
            type: "POST",
            url: "index.php?option=com_catalogue&task=remove_wishlist",
            data: "product_id=" + a,
            success: function (c) {
                showConfirm($("#removewishlist_confirm").val())
            }
        });
        $("#addwishlist").show()
    });
    $(".gotop").click(function () {
        $("body,html").animate({
            scrollTop: 0
        }, 400);
        return false
    });
    num_quantity = 0;
    num_design = 0;
    num_price = 0;
    t = 0;
    $(".vote").hover(function () {
        var a = $(this).attr("class");
        var g = a.substring(a.lastIndexOf(" ") + 1, a.length - 1);
        var h = a.substring(a.length - 1, a.length);
        for (i = 1; i <= h; i++) {
            var c = $("." + g + i).attr("class");
            $("." + g + i).removeClass(c).addClass("voteStar " + c)
        }
        appendSpan("#" + g + "_label", h)
    }, function () {
        $(".vote").each(function () {
            $(this).removeClass("voteStar ")
        });
        for (i = 1; i <= num_quantity; i++) {
            var a = $(".quantity" + i).attr("class");
            $(".quantity" + i).removeClass(a).addClass("voteStar " + a)
        }
        appendSpan("#quantity_label", num_quantity);
        for (i = 1; i <= num_design; i++) {
            var a = $(".design" + i).attr("class");
            $(".design" + i).removeClass(a).addClass("voteStar " + a)
        }
        appendSpan("#design_label", num_design);
        for (i = 1; i <= num_price; i++) {
            var a = $(".price" + i).attr("class");
            $(".price" + i).removeClass(a).addClass("voteStar " + a)
        }
        appendSpan("#price_label", num_price);
        t = (parseInt(num_quantity) + parseInt(num_design) + parseInt(num_price));
        sumVote(t)
    });
    $(".vote").click(function () {
        var a = $(this).attr("class");
        var e = a.substring(a.lastIndexOf(" ") + 1, a.length - 1);
        var f = a.substring(a.length - 1, a.length);
        switch (e.toString()) {
            case "quantity":
                num_quantity = f;
                break;
            case "design":
                num_design = f;
                break;
            case "price":
                num_price = f;
                break
        }
    });
    $("#send_cmt").click(function () {
        var p = "1";
        var o = $("#sortby").val();
        var l = $("#userID").val();
        var r = $("#userName").val();
        var m = r.substring(0, r.indexOf("@"));
        var s = $("#productID").val();
        var a = $("#loginLink").val();
        var q = t;
        var n = $("#comment").val();
        if (parseInt(t) == 0 || $.trim(n) == "") {
            showMessage($("#alert2").val());
            return false
        }
        if (parseInt(l) > 0) {
            $.ajax({
                type: "POST",
                url: "index.php?option=com_catalogue&task=review_post",
                data: "cmt=" + p + "&userid=" + l + "&nickname=" + m + "&productid=" + s + "&reviewtext=" + n + "&star=" + q + "&sortby=" + o,
                success: function (e) {
                    var c = $.parseJSON(e);
                    $("#content_cmt").hide().html(c.table).fadeIn(400);
                    $(".totalStar").hide().html(c.totalVoted).fadeIn(400);
                    var d = ($.browser.msie && parseInt($.browser.version) <= 7) ? "inline" : "inline-block";
                    $(".totalStar").css("display", d);
                    showMessage($("#alert4").val());
                    $("#comment").val("");
                    $(".subReview").find("span").removeClass("voteStar");
                    $(".sum_div").find("span").removeClass("voteSum").removeClass("voteSum_1").removeClass("voteSum_2");
                    $("#sum_label").empty();
                    $("#quantity_label").empty();
                    $("#design_label").empty();
                    $("#price_label").empty();
                    num_quantity = 0;
                    num_design = 0;
                    num_price = 0
                }
            })
        } else {
            var u = '<div id="login_wrap">' + $("#login_wrap_hidden").html() + "</div>";
            $.mycolorbox({
                title: $('#loginTitle').val(),
                html: u,
                transition: "none",
                onComplete: function () {
                    $(".login_form .email").focus();
                    $("#login_wrap").find(".login").click(function () {
                        var d = $("#login_wrap").height();
                        var c = $("#login_wrap").find(".email").val();
                        var h = $("#login_wrap").find(".passwd").val();
                        var j = $("#cur_url").val();
                        var k = $("#login_wrap .login_form input:last").attr("name");
                        var f = $("#login_wrap .login_form input:last").val();
                        var g = $("#login_wrap").find(".remember").is(":checked") ? 1 : 0;
                        if ($.trim(c) == "") {
                            $("#login_wrap .message").html($("#alert6").val());
                            $("#login_wrap .email").focus()
                        } else {
                            if (h == "") {
                                $("#login_wrap .message").html($("#alert7").val());
                                $("#login_wrap .passwd").focus()
                            } else {
                                if (checkEmail(c) && h != "") {
                                    $.ajax({
                                        type: "POST",
                                        url: "index.php?option=com_user&task=login",
                                        data: "username=" + c + "&passwd=" + h + "&remember=" + g + "&is_ajax=" + 1 + "&return=" + j + "&" + k + "=" + f,
                                        success: function (C) {
                                            $("#userID").val(C);
                                            if (parseInt(C) > 3) {
                                                var B = "1";
                                                var x = $("#sortby").val();
                                                var y = $("#userName").val();
                                                var A = y.substring(0, y.indexOf("@"));
                                                var D = $("#productID").val();
                                                var z = $("#loginLink").val();
                                                var v = t;
                                                var E = $("#comment").val();
                                                if (parseInt(t) == 0 || $.trim(E) == "") {
                                                    showMessage($("#alert2").val());
                                                    return false
                                                }
                                                $.ajax({
                                                    type: "POST",
                                                    url: "index.php?option=com_catalogue&task=review_post",
                                                    data: "cmt=" + B + "&userid=" + C + "&nickname=" + A + "&productid=" + D + "&reviewtext=" + E + "&star=" + v + "&sortby=" + x,
                                                    success: function (H) {
                                                        var G = $.parseJSON(H);
                                                        $("#content_cmt").hide().html(G.table).fadeIn(400);
                                                        $(".totalStar").hide().html(G.totalVoted).fadeIn(400);
                                                        var F = ($.browser.msie && parseInt($.browser.version) <= 7) ? "inline" : "inline-block";
                                                        $(".totalStar").css("display", F);
                                                        showMessage($("#alert4").val());
                                                        $("#comment").val("");
                                                        $(".subReview").find("span").removeClass("voteStar");
                                                        $(".sum_div").find("span").removeClass("voteSum").removeClass("voteSum_1").removeClass("voteSum_2");
                                                        $("#sum_label").empty();
                                                        $("#quantity_label").empty();
                                                        $("#design_label").empty();
                                                        $("#price_label").empty();
                                                        num_quantity = 0;
                                                        num_design = 0;
                                                        num_price = 0
                                                    }
                                                })
                                            } else {
                                                if (parseInt(C) == 0) {
                                                    $("#login_wrap .message").html($("#alert8").val())
                                                } else {
                                                    if (parseInt(C) == 2) {
                                                        $("#login_wrap .message").html($("#alert9").val())
                                                    } else {
                                                        $("#login_wrap .message").html($("#alert10").val())
                                                    }
                                                }
                                                var w = $("#login_wrap").height();
                                                resizeMyColorBox(parseInt(w) - parseInt(d))
                                            }
                                        }
                                    })
                                } else {
                                    $("#login_wrap .message").html($("#alert5").val());
                                    $("#login_wrap .email").focus()
                                }
                            }
                        }
                        var e = $("#login_wrap").height();
                        resizeMyColorBox(parseInt(e) - parseInt(d))
                    });
                    $("#login_wrap").find(".passwd").keyup(function (c) {
                        if (c.keyCode == 13) {
                            $("#login_wrap").find(".login").trigger("click")
                        }
                    });
                    $("#login_wrap").find(".remember").keyup(function (c) {
                        if (c.keyCode == 13) {
                            $("#login_wrap").find(".login").trigger("click")
                        }
                    })
                }
            })
        }
    });
    gotoPage(1, $("#sortby").val(), false);
    $("#sortby").change(function () {
        gotoPage(1, $("#sortby").val())
    });
    $(".short_cmt").live("click", function () {
        $(this).addClass("hide");
        $(this).parent().find(".full_cmt").removeClass("hide")
    });
    $(".full_cmt").live("click", function () {
        $(this).addClass("hide");
        $(this).parent().find(".short_cmt").removeClass("hide")
    });
    $(document).ready(function () {
        $('.fgItem').each(function () {
            $(this).qtip({
                content: {
                    text: $(this).next('div')
                },
                style: {
                    name: "blue",
                    width: "200"
                },
                position: {
                    adjust: {
                        x: 5,
                        y: 5
                    },
                    target: 'mouse'
                }
            });
        });
    });
    $(".downloadcp").live("click", function () {
        var d = $(this).attr("rel");
        var a = '<div id="scjbox" class="cpbox">' + $(d).html() + "</div>";
        $.colorbox({
            html: a,
            width: "428",
            transition: "none"
        })
    });
    $("a.download_coupon").live("click", function () {
        var d = $(this).attr("rel");
        var a = $("#lang").val();
        $("#cboxContent .cpmessage").html('<img src="templates/scj_en/images/ajax-loader.gif" title="loading" />');
        $.ajax({
            url: "index.php?option=com_coupon&task=download&lang=" + a,
            type: "POST",
            cache: false,
            data: "id=" + d,
            success: function (f) {
                if ($("#cboxWrapper").length > 0) {
                    $("body").scrollTo("#cboxWrapper")
                }
                $("#cboxContent .cpmessage").empty();
                if (f == $("#needlogin").val()) {
                    var c = $("#linklogin").val();
                    if (c.indexOf("lang=") == -1) {
                        c = c + "?dcdegree=" + d
                    } else {
                        c = c + "&dcdegree=" + d
                    }
                    window.location.href = c;
                    return false
                } else {
                    $("#cboxContent .cpmessage").html(f);
                    return false
                }
            },
            error: function () {
                alert("Something wrong");
                return false
            }
        })
    })
});
$(window).load(function () {
    $("#buynow, #addtocart").css("display", "block")
});

function appendSpan(c, d) {
    $(c + " span").remove();
    switch (d.toString()) {
        case "1":
            $(c).append("<span>" + $("#level1").val() + "</span>");
            break;
        case "2":
            $(c).append("<span>" + $("#level2").val() + "</span>");
            break;
        case "3":
            $(c).append("<span>" + $("#level3").val() + "</span>");
            break;
        case "4":
            $(c).append("<span>" + $("#level4").val() + "</span>");
            break;
        case "5":
            $(c).append("<span>" + $("#level5").val() + "</span>");
            break;
        default:
            break
    }
}

function sumVote(e) {
    var f = ~ ~(e / 3);
    var h = e % 3;
    var g = 1;
    for (i = 1; i <= 5; i++) {
        $(".sum_star" + i).removeClass("voteSum");
        $(".sum_star" + i).removeClass("voteSum_1");
        $(".sum_star" + i).removeClass("voteSum_2")
    }
    for (g = 1; g <= parseInt(f); g++) {
        $(".sum_star" + g).addClass("voteSum")
    }
    switch (h) {
        case 1:
            $(".sum_star" + g).addClass("voteSum_1");
            break;
        case 2:
            $(".sum_star" + g).addClass("voteSum_2");
            break
    }
    if (h == 2) {
        f++
    }
    appendSpan("#sum_label", parseInt(f))
}

function addToCartSubmit(n) {
    var h = $("#lang").val();
    var k = $("#productID").val();
    var j = $("#quantity").val();
    var o = $("#unit_code").val();
    var l = "index.php?option=com_payment&task=cartadd";
    var m = $("#linktocartlist").val();
    if ($('#chooseGift').length > 0) {
        $.mycolorbox({
            title: $('#chooseGiftTitle').val(),
            inline: true,
            href: "#giftPopup",
            transition: "none",
            width: "330",
            onComplete: function () {
                $('.giftOK').live('click', function () {
                    var w = $('select[name="giftList[]"]:not(:disabled) option:selected ');
                    var gift = new Array();
                    var gift_data = '';
                    $(w).each(function (i, value) {
                        gift[i] = 'giftList[]=' + $(value).attr('value');
                    });
                    if (gift.length > 0) {
                        gift_data = '&' + gift.join('&');
                    }
                    //alert(gift_data);return;
                    $.ajax({
                        type: "POST",
                        url: "index.php?option=com_catalogue&task=addCartListTable",
                        data: "product_id=" + k + "&unit_code=" + o + "&quantity=" + j,
                        success: function (a) { }
                    });
                    $('.freeze').show();
                    $('.processing').show();
                    if (n == 1) {
                        $.ajax({
                            type: "POST",
                            url: l,
                            data: "productID=" + k + "&unit_code=" + o + "&quantity=" + j + "&buyNow=" + 1 + "&lang=" + h + gift_data,
                            success: function (a) {
                                var b = $.parseJSON(a);
                                if (!b.result) {
                                    showMessage(b.message)
                                } else {
                                    window.location = m
                                }
                                return
                            }
                        })
                    } else {
                        $.ajax({
                            type: "POST",
                            url: l,
                            data: "productID=" + k + "&unit_code=" + o + "&quantity=" + j + "&ajax=" + 1 + "&lang=" + h + gift_data,
                            success: function (a) {
                                var b = $.parseJSON(a);
                                $('.freeze').hide();
                                $('.processing').hide();
                                $.mycolorbox.close();
                                showMessage(b.message);
                                return
                            }
                        })
                    }
                });
            },
            onClosed: function () {
                n = 0;
                return;
            }
        });

    } else {
        setTimeout(function () { $.mycolorbox.close() }, 200);
        $('.freeze').show();
        $('.processing').show();
        $.ajax({
            type: "POST",
            url: "index.php?option=com_catalogue&task=addCartListTable",
            data: "product_id=" + k + "&unit_code=" + o + "&quantity=" + j,
            success: function (a) { }
        });
        if (n == 1) {
            $.ajax({
                type: "POST",
                url: l,
                data: "productID=" + k + "&unit_code=" + o + "&quantity=" + j + "&buyNow=" + 1 + "&lang=" + h,
                success: function (a) {
                    var b = $.parseJSON(a);
                    if (!b.result) {
                        showMessage(b.message)
                    } else {
                        window.location = m
                    }
                    return
                }
            })
        } else {
            $.ajax({
                type: "POST",
                url: l,
                data: "productID=" + k + "&unit_code=" + o + "&quantity=" + j + "&ajax=" + 1 + "&lang=" + h,
                success: function (a) {
                    var b = $.parseJSON(a);
                    $('.freeze').hide();
                    $('.processing').hide();
                    showMessage(b.message);
                    setTimeout(function () { location.reload() }, 500)
                    return
                }
            })
        }
    }
}

function gotoPage(f, e, h) {
    if (h === undefined) {
        if ($(".commented_view").length > 0) {
            $("body").scrollTo(".commented_view", 200)
        }
        $(".loading").show()
    }
    var g = $("#productID").val();
    setTimeout(function () {
        $.ajax({
            type: "POST",
            url: "index.php?option=com_catalogue&task=review_post",
            data: "page=" + f + "&productid=" + g + "&sortby=" + e,
            success: function (c) {
                $(".loading").hide();
                var a = $.parseJSON(c);
                $("#content_cmt").hide().html(a.table).fadeIn(400);
                $(".totalStar").hide().html(a.totalVoted).fadeIn(400);
                var b = ($.browser.msie && parseInt($.browser.version) <= 7) ? "inline" : "inline-block";
                $(".totalStar").css("display", b)
            }
        })
    }, 500)
}

function showMessage(b) {
    b = '<div class="error_box">' + b + "</div>";
    $.colorbox({
        html: b,
        transition: "none"
    })
}

function showConfirm(g) {
    var k = $("#yes").val();
    var f = $("#no").val();
    var h = $("#lang").val();
    var j = $("#linktowishlist").val();
    html = '<div class="confirm_box">';
    html += '<span class="msg">' + g + "</span>";
    html += '<span class="yes_btn">' + k + "</span>";
    html += '<span class="no_btn">' + f + "</span>";
    html += '<span class="dis_yes_btn"></span>';
    html += '<span class="dis_no_btn"></span>';
    html += "</div>";
    $.colorbox({
        html: html,
        transition: "none",
        onComplete: function () {
            $(".yes_btn").click(function () {
                $(window.location).attr("href", j)
            });
            $(".no_btn").click(function () {
                $.colorbox.close()
            })
        }
    })
}

function resizeColorBox(b) {
    $("#cboxLoadedContent").css("height", $("#cboxLoadedContent").height() + b + "px");
    $("#cboxContent").css("height", $("#cboxContent").height() + b + "px");
    $("#cboxMiddleLeft").css("height", $("#cboxMiddleLeft").height() + b + "px");
    $("#cboxMiddleRight").css("height", $("#cboxMiddleRight").height() + b + "px");
    $("#cboxWrapper").css("height", $("#cboxWrapper").height() + b + "px");
    $("#colorbox").css("height", $("#colorbox").height() + b + "px")
};